package com.zebra.remoting.protocol;

import com.zebra.common.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import lombok.*;

@Data
@ToString
@EqualsAndHashCode(of = {"cmd"})
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CommandProfile {
    private int cmd;
    private int commandType;
    private int processorType;
    private int poolType;
    private boolean verifyType;

    public void write(ByteBuf b) {
        ByteBufUtils.writeInt(b, this.cmd);
        ByteBufUtils.writeInt(b, commandType);
        ByteBufUtils.writeInt(b, this.processorType);
        ByteBufUtils.writeInt(b, this.poolType);
        ByteBufUtils.writeInt(b, verifyType ? 1 : 0);
    }

    public CommandProfile read(ByteBuf b) {
        this.cmd = ByteBufUtils.readInt(b);
        this.commandType = ByteBufUtils.readInt(b);
        this.processorType = ByteBufUtils.readInt(b);
        this.poolType = ByteBufUtils.readInt(b);
        this.verifyType = ByteBufUtils.readInt(b) == 1 ? true : false;
        return this;
    }
}
